package dvx.mp.ivisual.desktop.ui;

import java.beans.PropertyVetoException;
import java.io.Serializable;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;

public class MenuItemObject implements Serializable {
	/***/
	private static final long serialVersionUID = 1L;
	final private String packageName = "dvx.mp.ivisual.desktop.ui.";
	
	private JDesktopPane desk;
	
	private String label;
	private String className;
	
	private JInternalFrame activity;

	public MenuItemObject(JDesktopPane desk, String label, String className) {
		this.desk = desk;
		
		this.label = label;
		this.className = className;
	}
	
	@Override
	public String toString()	{
		return label;
	}
	
	public void showActivity()	{
		if(null == this.activity)	{
			this.createActivity();
			
			this.activity.show();
		}
		
		this.activity.toFront();
		try {
			this.activity.setSelected(true);
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		}
	}
	
	private void createActivity()	{
		try {
			this.activity = (JInternalFrame) Class.forName(this.packageName + this.className).newInstance();

			this.desk.add(this.activity);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
